package com.yuji.aacar.controller.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.yuji.aacar.R;
import com.yuji.aacar.controller.cartype.bean.CarBean;
import com.yuji.aacar.core.cores.fres.CoreImageLoader;

import java.util.List;

public class ChooseCarAdapter extends RecyclerView.Adapter<ChooseCarAdapter.ViewHolder>{

    protected Context mContext;
    protected List<CarBean> mDatas;
    protected LayoutInflater mInflater;

    public ChooseCarAdapter(Context mContext, List<CarBean> mDatas) {
        this.mContext = mContext;
        this.mDatas = mDatas;
        mInflater = LayoutInflater.from(mContext);
    }

    public List<CarBean> getDatas() {
        return mDatas;
    }

    public ChooseCarAdapter setDatas(List<CarBean> datas) {
        mDatas = datas;
        return this;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(mInflater.inflate(R.layout.activity_choose_car_item, parent, false));
    }

    @Override
    public void onBindViewHolder(ChooseCarAdapter.ViewHolder holder, int position) {
        final CarBean cityBean = mDatas.get(position);
        holder.carName.setText(cityBean.getCity());
        holder.content.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Toast.makeText(mContext, "pos:" + position, Toast.LENGTH_SHORT).show();
            }
        });
        CoreImageLoader.loadImage(holder.carImage, cityBean.getCarUrl());
        holder.brandId = cityBean.getBrandId();
        holder.brandUrl = cityBean.getCarUrl();
    }

    @Override
    public int getItemCount() {
        return mDatas != null ? mDatas.size() : 0;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        TextView carName;
        SimpleDraweeView carImage;
        View content;
        String brandId;
        String brandUrl;

        public ViewHolder(View itemView) {
            super(itemView);
            carName = (TextView) itemView.findViewById(R.id.choose_car_item_carname);
            carImage = (SimpleDraweeView) itemView.findViewById(R.id.choose_car_item_image);
            content = itemView.findViewById(R.id.choose_car_item_content);
        }

        public TextView getCarName() {
            return carName;
        }

        public void setCarName(TextView carName) {
            this.carName = carName;
        }

        public SimpleDraweeView getCarImage() {
            return carImage;
        }

        public void setCarImage(SimpleDraweeView carImage) {
            this.carImage = carImage;
        }

        public View getContent() {
            return content;
        }

        public void setContent(View content) {
            this.content = content;
        }

        public String getBrandId() {
            return brandId;
        }

        public void setBrandId(String brandId) {
            this.brandId = brandId;
        }

        public String getBrandUrl() {
            return brandUrl;
        }

        public void setBrandUrl(String brandUrl) {
            this.brandUrl = brandUrl;
        }

        @Override
        public String toString() {
            return "ViewHolder{" +
                    "carName=" + carName +
                    ", carImage=" + carImage +
                    ", content=" + content +
                    ", brandId='" + brandId + '\'' +
                    ", brandUrl='" + brandUrl + '\'' +
                    '}';
        }
    }
}
